import React from 'react';

import BaseAction from '../common/BaseAction';
import Constants from '../../common/Constants';

export default class CommonRequestDataAction extends BaseAction {
    constructor(props) {
        super(props);
    }

    call(caller, data) {
      this._baseCall(caller, data);
      this.caller.setState({
        viewStatus: 2,
      })
    }

    finish(data, isSucceed, response) {
      if(isSucceed) {
        let dic ={viewStatus: 3,isResponeUpdate: true,}
        let dataKey = this.data.dataKey||'data';
        dic[dataKey]=data;
        this.caller.setState(dic)
        this.onFinishSuccess(data, response);
      }
      else if (response) {
        if(response.status == 401) {
          this._dealUnauthorized(this.caller);
        }
        else {
          this.caller.setState({viewStatus: response.status})
        }
      }
      else {
        this.caller.setState({viewStatus: 400,isResponeUpdate:true,data:[]})
      }
    }

    onFinishSuccess(data, response){

    }
}
